package ItemBased;


import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.WritableComparable;


public class LongPairWritableComparable implements WritableComparable<LongPairWritableComparable>{

    /**
     * the first field
     */
    public long first;

    /**
     * the second field
     */
    public long second;

    public LongPairWritableComparable() {
    	
    }
    
    public LongPairWritableComparable(long t1, long t2) {
    	first = t1;
    	second = t2;
    }
    
    public LongPairWritableComparable(LongWritable t1, LongWritable t2) {
    	first = t1.get();
    	second = t2.get();
    }
    
  /* 
    public void setFirstText(String t1) {
            first.set(Long.parseLong(t1));
    }
   
    
    public void setSecondText(String t2) {
            second.set(Long.parseLong(t2));
    }
*/
    /**
     * get the first field
     *
     * @return the first field
     */
    public long getFirst() {
            return first;
    }

    /**
     * get the second field
     *
     * @return the second field
     */
    public long getSecond() {
            return second;
    }

    public LongPairWritableComparable get() {
        return this;
    }
    
    public void write(DataOutput out) throws IOException {
            out.writeLong(first);
            out.writeLong(second);
    }

    public void readFields(DataInput in) throws IOException {
            first = in.readLong();
            second = in.readLong();
    }
    
    public static LongPairWritableComparable read(DataInput in) throws IOException{
    	LongPairWritableComparable l = new LongPairWritableComparable();
    	l.readFields(in);
    	return l;
    }
    
    public String toString(){
    	return Long.toString(first) + " " + Long.toString(second);
    }

    public int compareTo(LongPairWritableComparable ip2) {
    	if(first != ip2.first){
    		return (first < ip2.first ? 0:1);
    	}
    	return (second <= ip2.second ? 0:1);
    }

    public int hashCode() {
            return (int)first ^ (int)second;
    }

    public boolean equals(Object o) {
            LongPairWritableComparable p = (LongPairWritableComparable) o;
            return (first == p.first && second == p.second);
    }
}
